<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
     
      <el-form-item label="货品名称" prop="merchandiseName">
        <el-input
          v-model="queryParams.merchandiseName"
          placeholder="请输入货品名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     
      <el-form-item label="货主名称" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入货主名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      
      <el-form-item label="是否是试剂" prop="reagent">
        <el-input
          v-model="queryParams.reagent"
          placeholder="请输入是否是试剂：0:-否，1-是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否进口危化品" prop="isimportDanger">
        <el-input
          v-model="queryParams.isimportDanger"
          placeholder="请输入是否进口危化品； 0-否，1-是"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['trace:yiqiMerchandise:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['trace:yiqiMerchandise:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['trace:yiqiMerchandise:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['trace:yiqiMerchandise:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="yiqiMerchandiseList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="" align="center" prop="id" />
      <el-table-column label="货品注册id(上海市危险化学品追溯码管理子系统)" align="center" prop="traceMerchandiseId" />
      <el-table-column label="货品名称" align="center" prop="merchandiseName" />
      <el-table-column label="货主 ID" align="center" prop="ownerId" />
      <el-table-column label="货主名称" align="center" prop="ownerName" />
      <el-table-column label="NRCC 安全信息码，NRCC二维码对应的URL 信息" align="center" prop="nrccUrl" />
      <el-table-column label="NRCC 安全信息码登记号" align="center" prop="nrccRegisterCode" />
      <el-table-column label="是否为混合物: 0-否，1-是" align="center" prop="isMixture" />
      <el-table-column label="2828 目录文件中的序号" align="center" prop="chemicalSerial" />
      <el-table-column label="2828目录中的名字，不在根据化学品技术说明书中的填写。追溯码赋码范围为名录里1-2827 项以及 2828 项中的 88 个小项。" align="center" prop="chemicalName" />
      <el-table-column label="成分：化学品名最少 1 个，最多 5 个；混合物必填" align="center" prop="mixChemicleName" />
      <el-table-column label="1-气体；2-液体；3-固体；4-气溶胶" align="center" prop="physicalState" />
      <el-table-column label="其他属性" align="center" prop="otherAttribute" />
      <el-table-column label="联合国编号(UN号), 参考2828 目录" align="center" prop="unCode" />
      <el-table-column label="CAS号；有则必填，参考2828 目录" align="center" prop="casCode" />
      <el-table-column label="危险性类别(GHS); 多项以英文逗号分隔" align="center" prop="riskGhsitemCategory" />
      <el-table-column label="危险货物类别" align="center" prop="riskItemCategory" />
      <el-table-column label="火灾危险性类别" align="center" prop="fireRisk" />
      <el-table-column label="化学结构：0-无机，1-有机" align="center" prop="organic" />
      <el-table-column label="剧毒品特性；0-否，1-是" align="center" prop="deleterious" />
      <el-table-column label="酸碱性：0-酸性，1-碱性" align="center" prop="acidBase" />
      <el-table-column label="监控化学品(禁化武)特性；0-否，1-是" align="center" prop="monitored" />
      <el-table-column label="特别管控危险化学品特性：0-否，1-是" align="center" prop="specialControlled" />
      <el-table-column label="重点监管危险化学品特性  0-否，1-是" align="center" prop="regulatory" />
      <el-table-column label="上海禁限控化学品特性" align="center" prop="prohibited" />
      <el-table-column label="公安易制毒特性；0:否，1：是" align="center" prop="easyMadeDrug" />
      <el-table-column label="公安易制爆特性；0:否，1：是" align="center" prop="easyToExplode" />
      <el-table-column label="重大危险源申报临界值；单位吨，若无填写：999999" align="center" prop="criticalQuantity" />
      <el-table-column label="适用消防措施多项以英文逗号分隔" align="center" prop="fireFightingMeasures" />
      <el-table-column label="混放禁忌化学品名@联合国编号@CAS 号多项以“#”分隔" align="center" prop="mixedTaboo" />
      <el-table-column label="《化学品安全技术说明书》上传市局系统后获得的路径" align="center" prop="chemicalIdentificationReport" />
      <el-table-column label="进口危化品鉴定报告上传市局系统后获得的路径" align="center" prop="chemicalAppraisalReport" />
      <el-table-column label="密度值" align="center" prop="density" />
      <el-table-column label="密度单位：千克/立方米" align="center" prop="densityUnit" />
      <el-table-column label="浓度；百分比，保留 2 位小数" align="center" prop="concentration" />
      <el-table-column label="规格数量，保留 2 位小数" align="center" prop="unitCount" />
      <el-table-column label="质量计量单位；毫克" align="center" prop="unit" />
      <el-table-column label="包装单位名称" align="center" prop="specification" />
      <el-table-column label="是否是试剂：0:-否，1-是" align="center" prop="reagent" />
      <el-table-column label="生产行为；生产企业必填" align="center" prop="sourceType" />
      <el-table-column label="是否进口危化品； 0-否，1-是" align="center" prop="isimportDanger" />
      <el-table-column label="进口包装类别 1、2、3" align="center" prop="importDangerPackType" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['trace:yiqiMerchandise:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['trace:yiqiMerchandise:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改货品信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="货品注册id(上海市危险化学品追溯码管理子系统)" prop="traceMerchandiseId">
          <el-input v-model="form.traceMerchandiseId" placeholder="请输入货品注册id(上海市危险化学品追溯码管理子系统)" />
        </el-form-item>
        <el-form-item label="货品名称" prop="merchandiseName">
          <el-input v-model="form.merchandiseName" placeholder="请输入货品名称" />
        </el-form-item>
        <el-form-item label="货主 ID" prop="ownerId">
          <el-input v-model="form.ownerId" placeholder="请输入货主 ID" />
        </el-form-item>
        <el-form-item label="货主名称" prop="ownerName">
          <el-input v-model="form.ownerName" placeholder="请输入货主名称" />
        </el-form-item>
        <el-form-item label="NRCC 安全信息码，NRCC二维码对应的URL 信息" prop="nrccUrl">
          <el-input v-model="form.nrccUrl" placeholder="请输入NRCC 安全信息码，NRCC二维码对应的URL 信息" />
        </el-form-item>
        <el-form-item label="NRCC 安全信息码登记号" prop="nrccRegisterCode">
          <el-input v-model="form.nrccRegisterCode" placeholder="请输入NRCC 安全信息码登记号" />
        </el-form-item>
        <el-form-item label="是否为混合物: 0-否，1-是" prop="isMixture">
          <el-input v-model="form.isMixture" placeholder="请输入是否为混合物: 0-否，1-是" />
        </el-form-item>
        <el-form-item label="2828 目录文件中的序号" prop="chemicalSerial">
          <el-input v-model="form.chemicalSerial" placeholder="请输入2828 目录文件中的序号" />
        </el-form-item>
        <el-form-item label="2828目录中的名字，不在根据化学品技术说明书中的填写。追溯码赋码范围为名录里1-2827 项以及 2828 项中的 88 个小项。" prop="chemicalName">
          <el-input v-model="form.chemicalName" placeholder="请输入2828目录中的名字，不在根据化学品技术说明书中的填写。追溯码赋码范围为名录里1-2827 项以及 2828 项中的 88 个小项。" />
        </el-form-item>
        <el-form-item label="成分：化学品名最少 1 个，最多 5 个；混合物必填" prop="mixChemicleName">
          <el-input v-model="form.mixChemicleName" placeholder="请输入成分：化学品名最少 1 个，最多 5 个；混合物必填" />
        </el-form-item>
        <el-form-item label="1-气体；2-液体；3-固体；4-气溶胶" prop="physicalState">
          <el-input v-model="form.physicalState" placeholder="请输入1-气体；2-液体；3-固体；4-气溶胶" />
        </el-form-item>
        <el-form-item label="其他属性" prop="otherAttribute">
          <el-input v-model="form.otherAttribute" placeholder="请输入其他属性" />
        </el-form-item>
        <el-form-item label="联合国编号(UN号), 参考2828 目录" prop="unCode">
          <el-input v-model="form.unCode" placeholder="请输入联合国编号(UN号), 参考2828 目录" />
        </el-form-item>
        <el-form-item label="CAS号；有则必填，参考2828 目录" prop="casCode">
          <el-input v-model="form.casCode" placeholder="请输入CAS号；有则必填，参考2828 目录" />
        </el-form-item>
        <el-form-item label="危险性类别(GHS); 多项以英文逗号分隔" prop="riskGhsitemCategory">
          <el-input v-model="form.riskGhsitemCategory" placeholder="请输入危险性类别(GHS); 多项以英文逗号分隔" />
        </el-form-item>
        <el-form-item label="危险货物类别" prop="riskItemCategory">
          <el-input v-model="form.riskItemCategory" placeholder="请输入危险货物类别" />
        </el-form-item>
        <el-form-item label="火灾危险性类别" prop="fireRisk">
          <el-input v-model="form.fireRisk" placeholder="请输入火灾危险性类别" />
        </el-form-item>
        <el-form-item label="化学结构：0-无机，1-有机" prop="organic">
          <el-input v-model="form.organic" placeholder="请输入化学结构：0-无机，1-有机" />
        </el-form-item>
        <el-form-item label="剧毒品特性；0-否，1-是" prop="deleterious">
          <el-input v-model="form.deleterious" placeholder="请输入剧毒品特性；0-否，1-是" />
        </el-form-item>
        <el-form-item label="酸碱性：0-酸性，1-碱性" prop="acidBase">
          <el-input v-model="form.acidBase" placeholder="请输入酸碱性：0-酸性，1-碱性" />
        </el-form-item>
        <el-form-item label="监控化学品(禁化武)特性；0-否，1-是" prop="monitored">
          <el-input v-model="form.monitored" placeholder="请输入监控化学品(禁化武)特性；0-否，1-是" />
        </el-form-item>
        <el-form-item label="特别管控危险化学品特性：0-否，1-是" prop="specialControlled">
          <el-input v-model="form.specialControlled" placeholder="请输入特别管控危险化学品特性：0-否，1-是" />
        </el-form-item>
        <el-form-item label="重点监管危险化学品特性  0-否，1-是" prop="regulatory">
          <el-input v-model="form.regulatory" placeholder="请输入重点监管危险化学品特性  0-否，1-是" />
        </el-form-item>
        <el-form-item label="上海禁限控化学品特性" prop="prohibited">
          <el-input v-model="form.prohibited" placeholder="请输入上海禁限控化学品特性" />
        </el-form-item>
        <el-form-item label="公安易制毒特性；0:否，1：是" prop="easyMadeDrug">
          <el-input v-model="form.easyMadeDrug" placeholder="请输入公安易制毒特性；0:否，1：是" />
        </el-form-item>
        <el-form-item label="公安易制爆特性；0:否，1：是" prop="easyToExplode">
          <el-input v-model="form.easyToExplode" placeholder="请输入公安易制爆特性；0:否，1：是" />
        </el-form-item>
        <el-form-item label="重大危险源申报临界值；单位吨，若无填写：999999" prop="criticalQuantity">
          <el-input v-model="form.criticalQuantity" placeholder="请输入重大危险源申报临界值；单位吨，若无填写：999999" />
        </el-form-item>
        <el-form-item label="适用消防措施多项以英文逗号分隔" prop="fireFightingMeasures">
          <el-input v-model="form.fireFightingMeasures" placeholder="请输入适用消防措施多项以英文逗号分隔" />
        </el-form-item>
        <el-form-item label="混放禁忌化学品名@联合国编号@CAS 号多项以“#”分隔" prop="mixedTaboo">
          <el-input v-model="form.mixedTaboo" placeholder="请输入混放禁忌化学品名@联合国编号@CAS 号多项以“#”分隔" />
        </el-form-item>
        <el-form-item label="《化学品安全技术说明书》上传市局系统后获得的路径" prop="chemicalIdentificationReport">
          <el-input v-model="form.chemicalIdentificationReport" placeholder="请输入《化学品安全技术说明书》上传市局系统后获得的路径" />
        </el-form-item>
        <el-form-item label="进口危化品鉴定报告上传市局系统后获得的路径" prop="chemicalAppraisalReport">
          <el-input v-model="form.chemicalAppraisalReport" placeholder="请输入进口危化品鉴定报告上传市局系统后获得的路径" />
        </el-form-item>
        <el-form-item label="密度值" prop="density">
          <el-input v-model="form.density" placeholder="请输入密度值" />
        </el-form-item>
        <el-form-item label="密度单位：千克/立方米" prop="densityUnit">
          <el-input v-model="form.densityUnit" placeholder="请输入密度单位：千克/立方米" />
        </el-form-item>
        <el-form-item label="浓度；百分比，保留 2 位小数" prop="concentration">
          <el-input v-model="form.concentration" placeholder="请输入浓度；百分比，保留 2 位小数" />
        </el-form-item>
        <el-form-item label="规格数量，保留 2 位小数" prop="unitCount">
          <el-input v-model="form.unitCount" placeholder="请输入规格数量，保留 2 位小数" />
        </el-form-item>
        <el-form-item label="质量计量单位；毫克" prop="unit">
          <el-input v-model="form.unit" placeholder="请输入质量计量单位；毫克" />
        </el-form-item>
        <el-form-item label="包装单位名称" prop="specification">
          <el-input v-model="form.specification" placeholder="请输入包装单位名称" />
        </el-form-item>
        <el-form-item label="是否是试剂：0:-否，1-是" prop="reagent">
          <el-input v-model="form.reagent" placeholder="请输入是否是试剂：0:-否，1-是" />
        </el-form-item>
        <el-form-item label="是否进口危化品； 0-否，1-是" prop="isimportDanger">
          <el-input v-model="form.isimportDanger" placeholder="请输入是否进口危化品； 0-否，1-是" />
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listYiqiMerchandise, getYiqiMerchandise, delYiqiMerchandise, addYiqiMerchandise, updateYiqiMerchandise } from "@/api/trace/yiqiMerchandise";

export default {
  name: "YiqiMerchandise",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 货品信息表格数据
      yiqiMerchandiseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        traceMerchandiseId: null,
        merchandiseName: null,
        ownerId: null,
        ownerName: null,
        nrccUrl: null,
        nrccRegisterCode: null,
        isMixture: null,
        chemicalSerial: null,
        chemicalName: null,
        mixChemicleName: null,
        physicalState: null,
        otherAttribute: null,
        unCode: null,
        casCode: null,
        riskGhsitemCategory: null,
        riskItemCategory: null,
        fireRisk: null,
        organic: null,
        deleterious: null,
        acidBase: null,
        monitored: null,
        specialControlled: null,
        regulatory: null,
        prohibited: null,
        easyMadeDrug: null,
        easyToExplode: null,
        criticalQuantity: null,
        fireFightingMeasures: null,
        mixedTaboo: null,
        chemicalIdentificationReport: null,
        chemicalAppraisalReport: null,
        density: null,
        densityUnit: null,
        concentration: null,
        unitCount: null,
        unit: null,
        specification: null,
        reagent: null,
        sourceType: null,
        isimportDanger: null,
        importDangerPackType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询货品信息列表 */
    getList() {
      this.loading = true;
      listYiqiMerchandise(this.queryParams).then(response => {
        this.yiqiMerchandiseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        traceMerchandiseId: null,
        merchandiseName: null,
        ownerId: null,
        ownerName: null,
        nrccUrl: null,
        nrccRegisterCode: null,
        isMixture: null,
        chemicalSerial: null,
        chemicalName: null,
        mixChemicleName: null,
        physicalState: null,
        otherAttribute: null,
        unCode: null,
        casCode: null,
        riskGhsitemCategory: null,
        riskItemCategory: null,
        fireRisk: null,
        organic: null,
        deleterious: null,
        acidBase: null,
        monitored: null,
        specialControlled: null,
        regulatory: null,
        prohibited: null,
        easyMadeDrug: null,
        easyToExplode: null,
        criticalQuantity: null,
        fireFightingMeasures: null,
        mixedTaboo: null,
        chemicalIdentificationReport: null,
        chemicalAppraisalReport: null,
        density: null,
        densityUnit: null,
        concentration: null,
        unitCount: null,
        unit: null,
        specification: null,
        reagent: null,
        sourceType: null,
        isimportDanger: null,
        importDangerPackType: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加货品信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getYiqiMerchandise(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改货品信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateYiqiMerchandise(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addYiqiMerchandise(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除货品信息编号为"' + ids + '"的数据项？').then(function() {
        return delYiqiMerchandise(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('trace/yiqiMerchandise/export', {
        ...this.queryParams
      }, `yiqiMerchandise_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
